<%@page import="java.util.ArrayList"%>
<%@page import="cn.jhc.bean.NewsBean"%>
<%@page import="cn.jhc.dao.ConnectionFactory"%>
<%@page import="cn.jhc.dao.NewsDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/news.css"></link>
<style>
* {
	border: 0;
}
</style>
<title>校园新闻</title>
</head>
<body>
	<%
		int CurrentPage = 1;
		int intPageCount;
		if (request.getParameter("page") != null)
			CurrentPage = Integer.parseInt(request.getParameter("page"));
		if (CurrentPage < 1)
			CurrentPage = 1;
		int newsCount = 15;
	%>
	<div id="wrapper">
		<jsp:include page="./header.jsp"></jsp:include>
		<div id="address">
			<a>当前位置：　新闻中心</a>
		</div>
		<div id="wrapperdown">
			<%
				ArrayList<NewsBean> list = new ArrayList<NewsBean>();
				NewsDAO dao = new NewsDAO();
				dao.setCon(ConnectionFactory.getConnection());
				list = dao.getAllNews(CurrentPage, newsCount);
				request.setAttribute("news", list);
			%>
			<%
				NewsDAO dao2 = new NewsDAO();
				dao2.setCon(ConnectionFactory.getConnection());
				intPageCount = dao2.getCount(newsCount);
				if (intPageCount == 0) {
					CurrentPage = 1;
					intPageCount = 1;
				} else {
					if (CurrentPage > intPageCount)
						CurrentPage = intPageCount;
				}
			%>
			<div id="topall">
				<table align="left" width="1000">
					<tr>
						<th>标题</th>
						<th>时间</th>
					</tr>
					<c:forEach items="${requestScope.news}" var="news">
						<tr>
							<td height="30"><a href="newscontext.jsp?id=${news.id}">${news.title}</a></td>
							<td><div align="center">
									<a>${news.date}</a>
								</div></td>
						</tr>
					</c:forEach>
				</table>
			</div>
			<div id="page" align="right">
				<a>第<%=CurrentPage%>页 共<%=intPageCount%>页
				</a> <a href="news.jsp?page=<%=1%>">首页</a>
				<%
					if (CurrentPage > 1) {
				%>
				<a href="news.jsp?page=<%=CurrentPage - 1%>">上一页</a>
				<%
					} else {
				%>
				<a>上一页</a>
				<%
					}
				%>
				<%
					if (CurrentPage >= intPageCount) {
				%>
				<a>下一页</a>
				<%
					} else {
				%>
				<a href="news.jsp?page=<%=CurrentPage + 1%>">下一页</a>
				<%
					}
				%>
				<a href="news.jsp?page=<%=intPageCount%>">末页</a>
			</div>
		</div>
		<jsp:include page="./copyright.jsp"></jsp:include>
	</div>
</body>
</html>
